package com.caiyi.financial.nirvana.sms.handler;

import com.caiyi.financial.nirvana.sms.cache.BlackMobileCache;
import com.caiyi.financial.nirvana.sms.cache.SmsMateCache;
import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
import com.caiyi.financial.nirvana.sms.jedis.JedisService;
import com.caiyi.financial.nirvana.sms.thread.ApiActionThread;
import com.caiyi.financial.nirvana.sms.util.CommUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Created by Mario on 2017/12/20 0020.
 * 项目启动
 */
@Component
public class StartHandler extends ApplicationHandler {

    private static final Logger logger = LoggerFactory.getLogger(StartHandler.class);

    @Override
    public void start(ApplicationContext applicationContext) {
        long nodeId = 0;
        try {
            nodeId = JedisService.incr(JedisKey.SMS_NODE_ID);
        } catch (Exception e) {
        }
        if (nodeId >= 10) {
            CommUtil.NODE_ID = 1;
            JedisService.set(JedisKey.SMS_NODE_ID, "1");
        } else {
            CommUtil.NODE_ID = nodeId;
        }
        logger.info("api StartHandler nodeId : {}", nodeId);
        //加载黑名单到内存
        BlackMobileCache.initBlackMobile();
        //加载smsMate到内存
//        SmsMateCache.initSmsMateToLocal();
        //api订阅线程
        Runnable apiAction = new ApiActionThread();
        new Thread(apiAction).start();
    }


}
